$(function(){
    loadData();

    $('.board-tip').on('click', function () {
       var tip = $(this).attr('data-tip');
       if (!isNull(tip))
           wapAlert(tip);
    });

    $('.group-back-btn').on('click', function() {
        window.location.href = '/cloud/index';
    });

    $('.main-i-i1').on('click', function () {
       var url = $(this).attr('data-url');
       if (!isNull(url))
           window.location.href = url;

    });

});

function loadData() {
    $.showLoading();
    $.ajax({
        type: "POST",
        url: "/board/group/data",
        async: true,
        dataType: 'json',
        timeout: 25000,
        success: function (res) {
            $.hideLoading();
            console.log(res);
            if (res.code == 0) {
                //具体数据列表
                if (res.data != null) {
                    var data = res.data;
                    var deli = 0.0;
                    /**全站计划量**/
                    var plans = 0.0;
                    /**任务单数**/
                    var taskNum = 0;
                    /**发车车次**/
                    var trainNum = 0;
                    /**生产线**/
                    var proLine = 0;
                    /**空闲线**/
                    var freeLine = 0;
                    /**运输车辆**/
                    var tranCard = 0;
                    /**空闲车辆**/
                    var freeCard = 0;
                    var planStr = '';
                    var deliStr = '';
                    var taskStr = '';
                    var trainStr = '';
                    var proLineStr = '';
                    var freeLineStr = '';
                    var tranCardStr = '';
                    var freeCardStr = '';
                    $.each(data,function(index, val) {
                        deli += parseFloat(val.deli);
                        deliStr += val.name + ':' + parseFloat(val.deli).toFixed(1) + '方   ';
                        plans += parseFloat(val.plans);
                        planStr += val.name + ':' + parseFloat(val.plans).toFixed(1) + '方   ';
                        taskNum += parseInt(val.taskNum);
                        taskStr += val.name + ':' + parseInt(val.taskNum) + '单   ';
                        trainNum += parseInt(val.trainNum);
                        trainStr += val.name + ':' + parseInt(val.trainNum) + '次   ';
                        proLine += parseInt(val.proLine);
                        proLineStr += val.name + ':' + parseInt(val.proLine) + '条线   ';
                        freeLine += parseInt(val.freeLine);
                        freeLineStr += val.name + ':' + parseInt(val.freeLine) + '条线   ';
                        tranCard += parseInt(val.tranCard);
                        tranCardStr += val.name + ':' + parseInt(val.tranCard) + '辆   ';
                        freeCard += parseInt(val.freeCard);
                        freeCardStr += val.name + ':' + parseInt(val.freeCard) + '辆   ';
                    });
                    $('.board-plans').html(plans.toFixed(1));
                    $('.board-production').html(deli.toFixed(1));
                    $('.board-trainNum').html(trainNum);
                    $('.board-taskNum').html(taskNum);
                    $('.board-lineNum').html(proLine + '/' + freeLine);
                    $('.board-cardNum').html(tranCard + '/' + freeCard);

                    $('.board-plans-content').attr('data-tip', planStr);
                    $('.board-production-content').attr('data-tip', deliStr);
                    $('.board-trainNum-content').attr('data-tip', trainStr);
                    $('.board-taskNum-content').attr('data-tip', taskStr);
                    $('.board-lineNum-content').attr('data-tip', '正在生产搅拌楼[' + proLineStr + ']/空闲搅拌楼[' + freeLineStr + ']');
                    $('.board-cardNum-content').attr('data-tip', '正在运输车辆[' + tranCardStr + ']/空闲车辆[' + freeCardStr + ']');
                }
            } else {
                wapAlert(res.msg);
                return;
            }
        },
        error: function (res) {
            wapAlert("请求失败，请稍后再试！");
            $.hideLoading();
            return;
        },
        complete: function (XMLHttpRequest, status) {
            if (status == 'timeout') {
                wapAlert("请求超时，请稍后再试！");
                $.hideLoading();
                return;
            }
        }
    });
}